package acWing;

import java.util.Scanner;

public class _02CowSong {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String alphabet = scanner.next();
        String song = scanner.next();
        scanner.close();
        if (song.length() == 0){
            System.out.println(0);
            return;
        }
        int res = 1;
        int index;
        for (int i = 0;i < song.length()-1;i++){
            index = alphabet.indexOf(song.charAt(i));
            if (alphabet.indexOf(song.charAt(i+1)) <= index){
                res++;
            }
        }
        System.out.println(res);
    }
}
